<template>
    <div class="article-lists">
        <el-card class="!border-none" shadow="never">

            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="查询来源">
                    <el-select class="w-[280px]" v-model="queryParams.query_source" clearable>
                        <el-option label="全部" value="" />
                        <el-option label="通过推广" :value="1" />
                        <el-option label="自主查询" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item label="企业名称">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.company_name"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="统一社会信用代码">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.unified_social_credit_code"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="法人姓名">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.legal_representative_name"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="创建人">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.query_user_phone"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                 <el-form-item label="创建时间">
					<daterange-picker
						v-model:startTime="queryParams.start_time"
						v-model:endTime="queryParams.end_time"
                        type="daterange"
                        valueFormat="YYYY-MM-DD"
					/>
				</el-form-item>
                
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="序号" type="index" :index="indexAdd" min-width="100" />
                <!-- <el-table-column label="所属城市" min-width="120" prop="city_name">
                    <template #default="{row}">
                        <span v-if="row.city_name">{{ row.city_name }}</span>
                        <span v-else>-</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="报告ID" min-width="120" prop="id"/>
                <el-table-column label="企业名称" min-width="220" prop="company_name"/>
                <el-table-column label="统一社会信用代码" min-width="200" prop="unified_social_credit_code"/>
                <el-table-column label="法人姓名" min-width="180" prop="legal_representative_name"/>
                <el-table-column label="法人身份证号" min-width="180" prop="legal_representative_identity_no"/>
                <el-table-column label="法人手机号" min-width="180" prop="legal_representative_phone"/>
                <el-table-column label="查询来源" min-width="180" prop="query_source">
                    <template #default="{row}">
                        <span v-if="row.query_source == 1">通过推广</span>
                        <span v-if="row.query_source == 2">自主查询</span>
                    </template>
                </el-table-column>
                <el-table-column label="创建时间" min-width="180" prop="generate_time"/>
                <el-table-column label="创建人" min-width="180" prop="u_account">
                    <template #default="{row}">
                        <span v-if="row.u_accoun">{{ row.u_accoun }}</span>
                        <span v-else-if="row.eu_account">{{ row.eu_account }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="查询价（元）" min-width="180" prop="query_price"/>
                <el-table-column label="状态" min-width="180" prop="status">
                    <template #default="{row}">
                        <span v-if="row.status == 1">待生成</span>
                        <span v-if="row.status == 2">生成中</span>
                        <span v-if="row.status == 3">已生成</span>
                    </template>
                </el-table-column>

                <el-table-column label="操作" width="180" fixed="right">
                    <template #default="{ row }">
                        <el-button v-perms="['user.agent/agentData']" type="primary" link @click="handleSelectItem(row)">详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="list">
import { reportLists } from '@/api/qiye'
import { usePaging } from '@/hooks/usePaging'
import router, { getRoutePath } from '@/router'

const queryParams = reactive({
    query_source: '',
    company_name: '',
    unified_social_credit_code: '',
    legal_representative_name: '',
    start_time: '',
    end_time: '',
    query_user_phone: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: reportLists,
    params: queryParams
})

const indexAdd = (index: number) => {
    const page = pager.page // 当前页码
    const pagesize = pager.size // 每页条数
    return index + 1 + (page - 1) * pagesize
}

const handleSelectItem = (event: any) => {
    router.push({
        path: getRoutePath('workbench/reportDetail'), query: { id: event.id }
    })
}

onActivated(() => {
    getLists()
})

getLists()
</script>
<style lang="scss" scoped>
.txt{
    color: var(--el-color-primary);
}
</style>